#!/bin/sh
################################################################################
# log
################################################################################
. /etc/rc.d/functions

start() {

    local LOG_SERVER
    local LOG_SERVERS

    /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/log] Starting..."
    mm_message_output info "starting system logging ..."

    LOG_SERVERS=
    if [ -e /etc/log.conf ] ; then
        LOG_SERVERS=`/bin/cat /etc/log.conf \
                         | /bin/grep -e '^server '         \
                         | /bin/sed -e 's%[[:cntrl:]]% %g' \
                         | /bin/sed -e 's%  *% %g'         \
                         | /usr/bin/cut -d ' ' -f 2`
    fi
    LOG_SERVER=`/bin/echo ${LOG_SERVERS} \
                         | /bin/sed -e 's%[[:cntrl:]]% %g' \
                         | /bin/sed -e 's%  *% %g'         \
                         | /usr/bin/cut -d ' ' -f 1`
    if [ -n "${LOG_SERVER}" ] ; then
        /usr/bin/test -n "`/bin/pidof klogd`"   && /usr/bin/killall klogd
        /usr/bin/test -n "`/bin/pidof syslogd`" && /usr/bin/killall syslogd
        /sbin/syslogd -R "${LOG_SERVER}"
    fi
    /usr/bin/test -z "`/bin/pidof syslogd`" && /sbin/syslogd
    /usr/bin/test -z "`/bin/pidof klogd`"   && /sbin/klogd

    /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/log] Started with return code=0..."

    return 0
}

stop() {
    mm_message_output info "stopping system logging ..."

    /usr/bin/test -n "`/bin/pidof klogd`"   && /usr/bin/killall klogd
    /usr/bin/test -n "`/bin/pidof syslogd`" && /usr/bin/killall syslogd
}

case $1 in
    start) start ;;
    stop)  stop  ;;
esac

exit 0
